cmake_minimum_required(VERSION 3.2)
include(FindGSL) # This cmake module only exists in 3.2 and above

add_library(sekai SHARED 
	src/audioio.cpp
	src/midi.cpp
	src/common.cpp
	src/hzosc.cpp
	src/epr.cpp
	src/OLABuffer.cpp
	src/VoiceSampler.cpp
    src/VoiceDefESPEAK.cpp
    src/VoiceDefMBROLA.cpp
	src/Track.cpp
    src/UnisynIndex.cpp
    src/ControlTrack.cpp
    src/MBRSynth.cpp
    src/cheaptrick.cpp
	src/codec.cpp
	src/d4c.cpp
	src/dio.cpp
	src/fft.cpp
	src/harvest.cpp
	src/matlabfunctions.cpp
	src/stonemask.cpp
	src/synthesis.cpp
	src/synthesisrealtime.cpp
)

set(HEADERS 
	src/sekai/midi.h
	src/sekai/mfcc.h
	src/sekai/SekaiContext.h
	src/sekai/VVDReader.h
	src/sekai/OLABuffer.h
	src/sekai/VoiceSampler.h
    src/sekai/VoiceDefESPEAK.h
    src/sekai/VoiceDefMBROLA.h
	src/sekai/vvd.h
	src/sekai/common.h
	src/sekai/hzosc.h
	src/sekai/epr.h
	src/sekai/Track.h
    src/sekai/UnisynIndex.h
    src/sekai/MBRSynth.h
    src/sekai/EventList.h
    src/sekai/ControlTrack.h
    src/sekai/SynthInterface.h
)

ADD_DEFINITIONS(-std=c++11)

set(SEKAI_VERSION_MAJOR 0)
set(SEKAI_VERSION_MINOR 5)
set(SEKAI_VERSION_PATCH 0)
set(SEKAI_VERSION_STRING ${SEKAI_VERSION_MAJOR}.${SEKAI_VERSION_MINOR}.${SEKAI_VERSION_PATCH})
set_target_properties(sekai PROPERTIES VERSION ${SEKAI_VERSION_STRING}
                                           SOVERSION ${SEKAI_VERSION_MAJOR})
                                           
target_link_libraries(sekai fftw3 jsoncpp boost_system boost_filesystem GSL::gsl)
                                        
include(FindPkgConfig)
pkg_check_modules (JSONCPP REQUIRED jsoncpp)                                        
include_directories(src ${JSONCPP_INCLUDEDIR})

add_definitions ("-Wall")

install(FILES ${HEADERS} DESTINATION include/sekai)

EXECUTE_PROCESS(COMMAND dpkg-architecture -qDEB_HOST_MULTIARCH OUTPUT_VARIABLE
  CMAKE_ARCH_TRIPLET OUTPUT_STRIP_TRAILING_WHITESPACE)

add_executable(test_espeak test/test_espeak.cpp)
target_link_libraries(test_espeak sekai sndfile jack GSL::gsl GSL::gslcblas pthread)

add_executable(test_mbrola test/test_mbrola.cpp)
target_link_libraries(test_mbrola sekai sndfile jack GSL::gsl GSL::gslcblas pthread)

add_executable(test_unisyn test/test_unisyn.cpp)
target_link_libraries(test_unisyn sekai sndfile jack GSL::gsl GSL::gslcblas pthread)

add_executable(espeak-sg bin/espeak-sg.cpp)
target_link_libraries(espeak-sg espeak-ng)

add_executable(mbr-harvest bin/mbr-harvest.cpp)
target_link_libraries(mbr-harvest sekai sndfile)

add_executable(mbr-resynth bin/mbr-resynth.cpp)
target_link_libraries(mbr-resynth sekai sndfile)

add_executable(realtime_demo
examples/realtime_demo/jack.cpp
examples/realtime_demo/main.cpp
examples/realtime_demo/synth.cpp
)

target_link_libraries(realtime_demo sekai pthread jack sndfile)

install(TARGETS sekai espeak-sg #mbr-harvest mbr-resynth
        RUNTIME DESTINATION bin
        LIBRARY DESTINATION lib/${CMAKE_ARCH_TRIPLET}
)



